package com.example.nonacademic_education.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.example.nonacademic_education.constant.Constant;
import com.example.nonacademic_education.data.request.ProjectExcelVo;
import com.example.nonacademic_education.data.request.ProjectList;
import com.example.nonacademic_education.entity.Project;
import com.example.nonacademic_education.service.impl.ProjectServiceImpl;
import com.example.nonacademic_education.util.R;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author:yanghua
 * @Date:2023/4/18 19:42
 */
@RestController
@RequestMapping("project")
public class ProjectController {
    @Resource
    private ProjectServiceImpl projectService;
    @PostMapping("addOne")
    @SaCheckPermission("project.add")
    public R addOne(@RequestBody Project project){
        return projectService.addOne(project);
    }
    @DeleteMapping("deleteOne")
    @SaCheckPermission("project.delete")
    public R deleteOne(Long id){
        return projectService.deleteOne(id);
    }
    @PutMapping("updateOne")
    @SaCheckPermission("project.update")
    public R updateOne(@RequestBody Project project){
        return projectService.updateOne(project);
    }
    @PostMapping("getList")
    @SaCheckPermission("project.query")
    public R getList(@RequestBody ProjectList projectList,Integer item){
        return projectService.getList(projectList,item);
    }
    @PostMapping("getIdAndNameList")
    @SaCheckRole(Constant.NORMAL_ADMIN)
    public R getIdAndName(@RequestBody ProjectList projectList){
        return projectService.getIdAndName(projectList);
    }

    @PostMapping("exportStatisticsExcel")
    @SaCheckPermission("project.excel")
    public void exportStatisticsExcel(@RequestBody ProjectExcelVo projectExcelVo, HttpServletResponse response) throws IOException {
        projectService.exportStatisticsExcel(projectExcelVo,response);
    }
    @GetMapping("getTemplate")
    @SaCheckPermission("project.add")
    public void getTemplate(HttpServletResponse response) throws IOException {
        projectService.getTemplate(response);
    }
    @PostMapping("importProject")
    @SaCheckPermission("project.add")
    public R importProject(@RequestBody MultipartFile file) throws IOException {
        return projectService.importProject(file);
    }
}
